package com.sikhyeon.datastructure.model;

public class LinkedList {
    private Node head;

    public LinkedList() {
        this.head = null;
    }

    public void add(int value) {
        Node newNode = new Node(value);
        if (head == null) {
            head = newNode;
        } else {
            Node current = head;
            while (current.next != null) {
                current = current.next;
            }
            current.next = newNode;
        }
    }

    public void remove() {
        if (head != null) {
            if (head.next == null) {
                head = null;
            } else {
                Node current = head;
                while (current.next.next != null) {
                    current = current.next;
                }
                current.next = null;
            }
        }
    }

    public Node getHead() {
        return head;
    }

    public static class Node {
        public int value;
        public Node next;

        Node(int value) {
            this.value = value;
            this.next = null;
        }
    }
}
